(use-modules
 ;; for unit testing forms
 (srfi srfi-64))

(use-modules
 ;; import the module to test
 (web-path-handling)
 (path-handling))


(define path-to-current-dir
   (dirname (or (current-filename)
                (canonicalize-path "."))))


(define path-to-web-app-root
  (dirname
   (dirname
    (or (current-filename)
        (canonicalize-path ".")))))


(test-begin "web-path-handling-test")

(test-group
 "subpath?-test"

 (test-assert "subpath?--01"
   (subpath? (path-join "test-dir" "static")
                   (path-join "test-dir"))))

(test-group
 "safe-path?-test"

 (test-assert "safe-path?-test--01"
   (safe-path? "static" path-to-web-app-root))

 (test-assert "safe-path?-test--02"
   (not
    (safe-path? (path-join "static" "`" "eval" "`")
                path-to-web-app-root))))

;; Finish the testsuite, and report results.
(test-end "web-path-handling-test")
